package com.study.algorithm.base.common;

/**
 * MathUtil
 *
 * @author wanghuilong
 * @version 1.0
 * @description
 * @date 2023/2/28 21:00
 */
public class MathUtil {

    /**
     *
     * @param x 对数
     * @param b 底数
     * @return
     */
    public static int log(int x,int b) {
        return (int) (Math.log(x) / Math.log(b));
    }

    /**
     *
     * @param x 对数
     * @param b 底数
     * @return
     */
    public static double logDouble(double x,double b) {
        return (Math.log(x) / Math.log(b));
    }




    public static void main(String[] args) {
        double logValue = logDouble(12, 2);
        int log = log(12, 2);
        if(logValue > log) {
            log = log + 1;
        }
        System.out.println(log);
    }

}
